#ifndef NE_STL_INCLUDENE_STL_PUBLIC_H
#define NE_STL_INCLUDENE_STL_PUBLIC_H

#include "ne_stl_atomic.h"
#include "ne_stl_build.h"
#include "ne_stl_spinlock.h"
#include "ne_stl_type_traits.h"

namespace nstd {
struct default_context_t {};
using handle_t = uint32_t;
#ifndef INVALID_HANDLE
#define INVALID_HANDLE ((nstd::handle_t)0)
#endif
namespace {
struct def_max_handle_value : integral_constant<handle_t, 0x5FFFFFF7> {};
struct def_base_handle_value : integral_constant<handle_t, 0x30ABCDEF> {};
}  // namespace
template <typename TContext, handle_t _max_handle_value, handle_t _base_handle_value>
struct handle_generator_impl {
    static handle_t generate() {
        static handle_t _current_handle_value{_base_handle_value};
        static nstd::spinlock _generat_handle_lock;
        nstd::lock_guard __guard(_generat_handle_lock);
        if (_current_handle_value >= _max_handle_value) {
            _current_handle_value = _base_handle_value;
        }
        return ++_current_handle_value;
    }
};
using handle_generator = handle_generator_impl<default_context_t, def_max_handle_value::value, def_base_handle_value::value>;
struct _enum_converter {
    template <typename TEnum>
    static TEnum v(int32_t _i_v) {
        union {
            int32_t i_v;
            TEnum e_v;
        } u = {_i_v};
        return u.e_v;
    }
    template <typename TEnum>
    static int32_t v(TEnum _e_v) {
        union {
            TEnum e_v;
            int32_t i_v;
        } u = {_e_v};
        return u.i_v;
    }
};
using em_cove = _enum_converter;
template <typename TEnum, typename TIntegral, typename nstd::enable_if<std::is_integral<TIntegral>::value, std::nullptr_t>::type = nullptr>
TEnum& enum_cast(const TIntegral& _i_v) {
    union {
        const TIntegral* i_v;
        TEnum* e_v;
    } u{&_i_v};
    return *u.e_v;
}
template <typename TEnum>
int32_t& enum_cast(TEnum& _e_v) {
    union {
        TEnum* e_v;
        int32_t* i_v;
    } u{&_e_v};
    return *u.i_v;
}

template <typename T, size_t N>
char (&ArraySizeHelper(T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
}  // namespace nstd

#endif  // !NE_STL_INCLUDENE_STL_PUBLIC_H
